﻿using System;
using System.Diagnostics;
using Microsoft.Win32;

namespace WindowsAPI.RegistryEx
{
    public static class Tweeks
    {
        public static bool USBStoreLock
        {
            get
            {
                var LocalMachine = Registry.LocalMachine;
                var USBStoreKey = LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\UsbStor", true);

                Debug.Assert(USBStoreKey != null, "USBStoreKey != null");
                return USBStoreKey.GetValue("Start", "3").Equals(4);
            }
            set
            {
                Console.WriteLine(@"Get regystry key HKLM\");
                var LocalMachine = Registry.LocalMachine;
                Console.WriteLine(@"Get regystry subkey SYSTEM\CurrentControlSet\Services\UsbStor");
                var USBStoreKey = LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\UsbStor", true);

                Debug.Assert(USBStoreKey != null, "USBStoreKey != null");
                Console.WriteLine(@"Set value " + value);
                USBStoreKey.SetValue("Start", value ? 4 : 3);
            }
        }

        public static bool DisableTaskMgr
        {
            get
            {
                var CurrentUser = Registry.CurrentUser;
                var lv_DisableTaskMgrKey =
                            CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System", true);
                Debug.Assert(lv_DisableTaskMgrKey != null, "lv_DisableTaskMgrKey != null");
                return lv_DisableTaskMgrKey.GetValue("DisableTaskMgr", "0").Equals("1");
            }
            set
            {
                var CurrentUser = Registry.CurrentUser;
                var lv_DisableTaskMgrKey =
                            CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System", true);
                Debug.Assert(lv_DisableTaskMgrKey != null, "lv_DisableTaskMgrKey != null");
                lv_DisableTaskMgrKey.SetValue("DisableTaskMgr", value ? "1" : "0");
            }
        }
    }
}
